package www.openteam.com.presenter;

import android.util.Log;

import java.util.HashMap;
import java.util.List;

import www.openteam.com.base.BasePresenter;
import www.openteam.com.bean.Result;
import www.openteam.com.bean.ResultNew;
import www.openteam.com.contract.LoginContract;
import www.openteam.com.model.LoginModel;
import www.openteam.com.mvp.IModel;
import www.openteam.com.tool.LogUtils;
import www.openteam.com.ui.LoginActivity;

/**
 * Created by kylin on 2016/12/19.
 */

public class LoginPresenter extends
        BasePresenter<LoginActivity> implements
        LoginContract.LoginPresenter{
    @Override
    public HashMap<String, IModel> getiModelMap() {

        return loadModelMap(new LoginModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String ,IModel> map =new HashMap<>();
        map.put("login",models[0]);
        return map;
    }

    @Override
    public void login(final String name, String password) {
           if (!getIView().checkNull()){
               ((LoginModel)getiModelMap()
               .get("login")
               ).login(name, password, new LoginModel.LoginOnListener() {
                   @Override
                   public void successInfo(ResultNew result) {
                       getIView().loginSuccess(result);
                   }

                   @Override
                   public void failInfo(String str) {
                       LogUtils.d(LoginPresenter.class.getSimpleName() +
                               "r.failInfo", str);
                       getIView().loginFail(str);
                   }
               });


           }
    }
}
